'if you have already run the program you have noticed that the wave plot
'is a Static plot only.I am currently working on a Dynamic plot,a dynamic
'plotted wave shows while being played(as seen in the Windows 3.1 Sound Recorder)
'Anyone with tips on plotting dynamically in VB please post a
'bulletin,E-Mail or whatever.
Type SMPTE
hour As String * 1 ' hours
min As String * 1 ' minutes
sec As String * 1 ' seconds
frame As String * 1 ' frames
fps As String * 1 ' frames per second
dummy As String * 1 ' pad
End Type
Type MMTIME
wType As Integer ' indicates the contents of units
units As Long ' (msecs, samples, bytes)
SMPTEVal As SMPTE
songptrpos As Long ' song pointer position
End Type
Type WAVEOUTCAPS
wMid As Integer
wPid As Integer
vDriverVersion As Integer
szPName As String * 32
dwFormats As Long
wChannels As Integer
dwSupport As Long
End Type
Type WAVEFORMAT
wFormatTag As Integer
nChannels As Integer
nSamplesPerSec As Long
nAvgBytesPerSec As Long
nBlockAlign As Integer
End Type
Type PCMWAVEFORMAT
wf As WAVEFORMAT
wBitsPerSample As Integer
End Type
Type WAVEHDR
lpData As Long
dwBufferLength As Long
dwBytesRecorded As Long
dwUser As Long
dwFlags As Long
dwLoops As Long
lpNext As Long
reserved As Long
End Type
Type FOURCC
Chars As String * 4
End Type
Type MMIOINFO
dwFlags As Long
fccIOProc As FOURCC
lpIOProc As Long
wErrorRet As Integer
wReserved As Integer
' Fields maintained by MMIO functions during buffered IO
cchBuffer As Long
pchBuffer As Long
pchNext As Long
pchEndRead As Long
pchEndWrite As Long
lBufOffset As Long
' Fields maintained by I/O procedure
lDiskOffset As Long
adwInfo As String * 12
' Other fields maintained by MMIO
dwReserved1 As Long
dwReserved2 As Long
hMMIO As Integer
End Type
' RIFF chunk information data structure
Type MMCKINFO
CkId As FOURCC
CkSize As Long
fccType As FOURCC
dwDataOffset As Long
dwFlags As Long
End Type
Type MonoEightBitSamples
Char As String * 1
End Type
Type StereoEightBitSamples
LeftChar As String * 1
RightChar As String * 1
End Type
Type MonoSixteenBitSamples
Sample As Integer
End Type
Type StereoSixteenBitSamples
LeftSample As Integer
RightSample As Integer
End Type
Declare Function waveOutReset Lib "MMSYSTEM" (ByVal hWaveOut As Integer) As Integer
Declare Function waveOutGetDevCaps Lib "MMSystem" (ByVal wDeviceID As Integer, lpCaps As WAVEOUTCAPS, ByVal wSize As Integer) As Integer
Declare Function waveOutOpen Lib "MMSystem" (lphWaveOut As Integer, ByVal wDeviceID As Integer, lpFormat As Any, ByVal dwCallBack As Long, ByVal dwCallBack As Long, ByVal dwFlags As Long) As Integer
Declare Function waveOutClose Lib "MMSystem" (ByVal hWaveOut As Integer) As Integer
Declare Function waveOutPrepareHeader Lib "MMSystem" (ByVal hWaveOut As Integer, lpWaveOutHdr As Any, ByVal wSize As Integer) As Integer
Declare Function waveOutUnprepareHeader Lib "MMSystem" (ByVal hWaveOut As Integer, lpWaveOutHdr As Any, ByVal wSize As Integer) As Integer
Declare Function waveOutWrite Lib "MMSystem" (ByVal hWaveOut As Integer, lpWaveOutHdr As Any, ByVal wSize As Integer) As Integer
Declare Function waveOutGetPosition Lib "MMSYSTEM" (ByVal hWaveOut As Integer, lpinfo As MMTIME, ByVal uSize As Integer) As Integer
Declare Function mmioOpen Lib "MMSystem" (ByVal szFilename As String, lpMMIOINFO As Any, ByVal dwOpenFlags As Long) As Integer
Declare Function mmioClose Lib "MMSystem" (ByVal hMMIO As Integer, ByVal wFlags As Integer) As Integer
Declare Function mmioDescend Lib "MMSystem" (ByVal hMMIO As Integer, lpCk As Any, lpCkParent As Any, ByVal wFlags As Integer) As Integer
Declare Function mmioAscend Lib "MMSystem" (ByVal hMMIO As Integer, lpCk As Any, ByVal wFlags As Integer) As Integer
Declare Function mmioRead Lib "MMSystem" (ByVal hMMIO As Integer, pCh As Any, ByVal cCh As Long) As Long
Declare Function mmioReadToGlobal Lib "MMSystem" Alias "mmioRead" (ByVal hMMIO As Integer, ByVal lpBuffer As Long, ByVal cCh As Long) As Long
Declare Function lstrcpy Lib "Kernel" (lpString1 As Any, lpString2 As Any) As Long
Declare Function GlobalAlloc Lib "Kernel" (ByVal wFlags As Integer, ByVal dwBytes As Long) As Integer
Declare Function GlobalHandleToSel Lib "ToolHelp.DLL" (ByVal hMem As Integer) As Integer
Declare Function MemoryWrite Lib "ToolHelp.DLL" (ByVal wSel As Integer, ByVal dwOffSet As Long, lpvBuf As Any, ByVal dwcb As Long) As Long
Declare Function MemoryRead Lib "ToolHelp.DLL" (ByVal wSel As Integer, ByVal dwOffSet As Long, lpvBuf As Any, ByVal dwcb As Long) As Long
Declare Function GlobalFree Lib "Kernel" (ByVal hMem As Integer) As Integer
Declare Function AnsiNext Lib "User" (ByVal lpString As String) As Long
Declare Function GlobalLock Lib "Kernel" (ByVal hMem As Integer) As Long
Declare Function GlobalUnlock Lib "Kernel" (ByVal hMem As Integer) As Integer
Declare Sub hmemcpy Lib "Kernel" (ByVal lpDest As Long, ByVal lpSrc As Long, ByVal BytesToCopy As Long)
Declare Function mmsystemGetVersion Lib "MMSYSTEM" () As Integer
Declare Function mciexecute Lib "mmsystem" (ByVal lpstrCommand As String) As Integer
Declare Function mciSendCommand Lib "mmsystem" (ByVal udeviceid As Integer, ByVal uMessage As Integer, ByVal dwParam1 As Long, ByVal dwParam2 As Long) As Long
Declare Function mcisendstring Lib "mmsystem" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hWndCallback As Integer) As Long
Declare Function mciGetErrorString Lib "mmsystem" (ByVal wError As Long, ByVal lpstrBuffer As String, ByVal uLength As Integer) As Integer
Declare Function sndPlaySound Lib "MMSYSTEM" (ByVal lpszSoundName As String, ByVal uFlags As Integer) As Integer
Global wavepath As String
Global PCMWaveFmtRecord As PCMWAVEFORMAT
Global hWaveSampleData As Integer
Dim hWaveOut As Integer
Dim WaveHeader As WAVEHDR
Global plotpos As Integer
Global plottime As Single
'used for sndPlaySound
Global Const SND_SYNC = &H0 ' play synchronously (default)
Global Const SND_ASYNC = &H1 ' play asynchronously
Global Const SND_NODEFAULT = &H2 ' don't use default sound
Global Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
Global Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound
Global Const SND_NOSTOP = &H10 ' don't stop any currently playing sound
Global Const GMEM_MOVEABLE = &H2
Global Const GMEM_ZEROINIT = &H40
Global Const WAVE_MAPPER = -1 ' Device ID for Wave Mapper
Global Const MMIO_READ = &H0&
Global Const MMIO_WRITE = &H1&
Global Const MMIO_READWRITE = &H2&
Global Const MMIO_FINDCHUNK = &H10 ' mmioDescend: find a chunk by ID
Global Const MMIO_FINDRIFF = &H20 ' mmioDescend: find a LIST chunk
Global Const WHDR_DONE = &H1 ' done bit
' flags for dwFlags parameter in waveOutOpen() and waveInOpen()
Global Const WAVE_FORMAT_QUERY = &H1
Global Const TWIPS = 1
Global Const WAVECAPS_PITCH = &H1 ' Supports pitch control
Global Const WAVECAPS_PLAYBACKRATE = &H2 ' Supports playback rate control
Global Const WAVECAPS_VOLUME = &H4 ' Supports volume control
Global Const WAVECAPS_LRVOLUME = &H8 ' Supports separate left-right volume control
Global Const WAVECAPS_SYNC = &H10
' types for wType field in MMTIME struct
Global Const TIME_MS = &H1 ' time in milliseconds
Global Const TIME_SAMPLES = &H2 ' number of wave samples
Global Const TIME_BYTES = &H4 ' current byte offset
Global Const TIME_SMPTE = &H8 ' SMPTE time
Global Const TIME_MIDI = &H10 ' MIDI time
' MsgBox parameters
Global Const MB_OK = 0 ' OK button only
Global Const MB_OKCANCEL = 1 ' OK and Cancel buttons
Global Const MB_ABORTRETRYIGNORE = 2 ' Abort, Retry, and Ignore buttons
Global Const MB_YESNOCANCEL = 3 ' Yes, No, and Cancel buttons
Global Const MB_YESNO = 4 ' Yes and No buttons
Global Const MB_RETRYCANCEL = 5 ' Retry and Cancel buttons
Global Const MB_ICONSTOP = 16 ' Critical message
Global Const MB_ICONQUESTION = 32 ' Warning query
Global Const MB_ICONEXCLAMATION = 48 ' Warning message
Global Const MB_ICONINFORMATION = 64 ' Information message
' MsgBox return values
Global Const IDOK = 1 ' OK button pressed
Global Const IDCANCEL = 2 ' Cancel button pressed
Global Const IDABORT = 3 ' Abort button pressed
Global Const IDRETRY = 4 ' Retry button pressed
Global Const IDIGNORE = 5 ' Ignore button pressed
Global Const IDYES = 6 ' Yes button pressed
Global Const IDNO = 7 ' No button pressed
Global Const WAVE_INVALIDFORMAT = &H0 ' Invalid Format
Global Const WAVE_FORMAT_1M08 = &H1 ' 11.025 kHz, Mono, 8 bit
Global Const WAVE_FORMAT_1S08 = &H2 ' 11.025 kHz, Stereo, 8 bit
Global Const WAVE_FORMAT_1M16 = &H4 ' 11.025 kHz, Mono, 16 bit
Global Const WAVE_FORMAT_1S16 = &H8 ' 11.025 kHz, Stereo, 16 bit
Global Const WAVE_FORMAT_2M08 = &H10 ' 22.05 kHz, Mono, 8 bit
Global Const WAVE_FORMAT_2S08 = &H20 ' 22.05 kHz, Stereo, 8 bit
Global Const WAVE_FORMAT_2M16 = &H40 ' 22.05 kHz, Mono, 16 bit
Global Const WAVE_FORMAT_2S16 = &H80 ' 22.05 kHz, Stereo, 16 bit
Global Const WAVE_FORMAT_4M08 = &H100 ' 44.1 kHz, Mono, 8 bit
Global Const WAVE_FORMAT_4S08 = &H200 ' 44.1 kHz, Stereo, 8 bit
Global Const WAVE_FORMAT_4M16 = &H400 ' 44.1 kHz, Mono, 16 bit
Global Const WAVE_FORMAT_4S16 = &H800 ' 44.1 kHz, Stereo, 16 bit
Function checkformat (wavepath As String) As Integer
'check for the proper format tag
'THIS will go into the RIFF wave file and grab the format tag
'any format tag of 16777728(actually 2) will not load.
'A format tag of 2 is a 16 bit compressed file,converted down to 4 or 8 bit files
'having trouble opening and then Closing these files.
'without this procedure there will be problems with format 2 files on
'some sound cards/drivers
'It is a jerry rig at best but it Does work to prevent crashes
Dim fmt As Long, f As Integer
Const UNCOMPRESSED = 16777472
Const COMPRESSED = 16777728
f = FreeFile
Open wavepath For Binary As #f
'go to the 20th byte,this is the format tag
Get #f, 20, fmt
Close #f
Select Case fmt
Case UNCOMPRESSED
checkformat = True
Case COMPRESSED
checkformat = False
End Select
End Function
Sub CloseWavePlay ()
Dim dummy As Integer
If hWaveSampleData <> 0 Then
dummy = GlobalFree(hWaveSampleData)
End If
End Sub
Function ExtendGlobalMemBlock (hMemoryBlock As Integer, OldLength As Long, NewLength As Long) As Integer
Dim hNewMemoryBlock As Integer
Dim lpNewMemoryBlock As Long
Dim lpMemoryBlock As Long
Dim dummy As Integer
hNewMemoryBlock = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, NewLength)